package com.rj.bd.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.rj.bd.entity.Dingdan;
/**
 * 
 * @author 
 *
 */
@Mapper
public interface DingdanMapper {

	@Select("select * from dingdan ")
	List<Dingdan> queryAll();
	
	@Select("select dingdan.did did,user.uid uid,user.uname uname,user.unumber unumber,user.usex usex,book.bnum bnum,book.bname bname,class.cname,dingdan.zhuangtai zhuangtai from dingdan  LEFT JOIN book  ON  dingdan.bid=book.bid  LEFT JOIN user ON  dingdan.uid=user.uid  JOIN class ON  book.cid=class.cid where dingdan.did like #{did} limit #{start},#{end}")  
	List<Map> getPage(Map maps);
	
	@Select("select dingdan.did did,user.uid uid,user.uname uname,user.unumber unumber,user.usex usex,book.bnum bnum,book.bname bname,class.cname,dingdan.zhuangtai zhuangtai from dingdan  LEFT JOIN book  ON  dingdan.bid=book.bid  LEFT JOIN user ON  dingdan.uid=user.uid  JOIN class ON  book.cid=class.cid where dingdan.did like #{did}")  
	List<Dingdan> query(String did);
	
	@Select("select dingdan.did did,user.uid uid,user.uname uname,user.unumber unumber,user.usex usex,book.bnum bnum,book.bname bname,class.cname,dingdan.zhuangtai zhuangtai from dingdan  LEFT JOIN book  ON  dingdan.bid=book.bid  LEFT JOIN user ON  dingdan.uid=user.uid  JOIN class ON book.cid=class.cid where user.uid=#{uid} and dingdan.did like #{did} limit #{start},#{end}")  
	List<Map> getPageByUser(Map maps);

	
	//@Select("select dingdan.did did,user.uid uid,user.uname uname,user.unumber unumber,user.usex usex,book.bnum bnum,book.bname bname,class.cname,dingdan.zhuangtai zhuangtai from dingdan  LEFT JOIN book  ON  dingdan.bid=book.bid  LEFT JOIN user ON  dingdan.uid=user.uid  JOIN class ON book.cid=class.cid where user.uid=#{uid} and dingdan.did like #{did}")  
	@Select("select * from dingdan,book,user where dingdan.bid=book.bid and dingdan.uid=user.uid and user.uid=#{uid} and dingdan.did like #{did}")  
	List<Map> queryByUser(Map maps);

	@Insert("insert into dingdan values (#{did},#{user.uid},#{book.bid},#{dbegintime},#{dendtime},#{zhuangtai})")
	void add(Dingdan dingdan);
	
	@Select("select dingdan.did did,dingdan.dbegintime dbegintime,dingdan.dendtime dendtime from dingdan where uid=#{uid}")  
	List<Dingdan> queryByZhuangtai(String uid);

	@Update("UPDATE dingdan set zhuangtai='3' where uid=#{uid}")
	void editByUserZhuangtai(String uid);

	@Update("UPDATE dingdan set zhuangtai='2' where bid=#{bid}")
	void editByDingdanZhuangTaiWei(String bid);

	

	

	

}
